package com.ynet.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SendServerController extends HttpServlet {
	
	private final Logger logger = LoggerFactory.getLogger(SendServerController.class);

	private static final long serialVersionUID = 1L;

//	http://127.0.0.1:18080/penetrate-server/zhangsan.wan/api/ylb/loan/repayBatchYlb.do
//	http://127.0.0.1:18080/penetrate-server/zhangsan.lan/
	
//	http://127.0.0.1:18080/penetrate-server/logon.inner/		//登陆接口
//	http://127.0.0.1:18080/penetrate-server/register.inner/	//注册接口

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		StringBuffer url = request.getRequestURL();// http:localhost:8080/CarsiLogCenter_new/idpstat.jsp
		logger.debug("url: " + url);
		
		String uri = request.getRequestURI(); // CarsiLogCenter_new/idpstat.jsp
		logger.debug("uri: " + uri);
		
		String path = request.getContextPath();// CarsiLogCenter_new
		logger.debug("path: " + path);

		//lx760.do/userData/registNum&bsUserId=1&datav=1
		String uripath = uri.replaceAll(path + "/", "");		
		logger.debug("uripath: " + uripath);
		
		//获取 外网请求 appid
		int uripathWan = uripath.indexOf(".wan", 0);		
		logger.debug("uripathWan: " + uripathWan);
		
		//获取 内网请求 appid
		int uripathLan = uripath.indexOf(".lan", 0);		
		logger.debug("uripathLan: " + uripathLan);

		//内部请求
		int uripathInner = uripath.indexOf(".inner", 0);		
		logger.debug("uripathInner: " + uripathInner);

		//内部响应请求
		int uripathResWan = uripath.indexOf(".reswan", 0);		
		logger.debug("uripathResWan: " + uripathResWan);
		
		if(uripathWan != -1){
			UserManage.wanAppid(request, response);//公网访问请求处理
		} else if (uripathLan != -1){
			UserManage.lanAppid(request, response);//内网访问请求处理
		}else if(uripathInner != -1){

			String innerUrl = uripath.substring(0, uripathInner);
			switch (innerUrl) {

			case "logon"://用户登陆
				UserManage.logon(request, response);
				break;

			case "register"://用户注册
				UserManage.register(request, response);
				break;

			default:
				System.out.println("其他" + innerUrl);
			}
			
		}else if(uripathResWan != -1){
			UserManage.reswan(request, response);//内网访问响应处理
		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
